﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace iS3.Server.MetaConfig.Models
{
    public class DataModelTemplate
    {
        public string Name { get; set; }
        public string Code { get; set; }
        public string Type { get; set; }
        public string Desc { get; set; }
        public string DomainType { get; set; }
        public string BaseDMTCode { get; set; }
        public string RefStandardCode { get; set; }

        public bool Authentication { get; set; } = false;

        public string EntityViewType { get; set; }   //可视化组件
        public string DefaultViewPath { get; set; }   //可视化默认路径
        public bool DefaultView2Pos { get; set; } = false;

        public List<PropertyMate> PropertyMetas { get; set; }
        public List<DataModelRelation> Relations { get; set; }
        public List<InheritanceRelation> InheritanceRelations { get; set; }

        public DataModelTemplate()
        {
            PropertyMetas = new List<PropertyMate>();
            Relations = new List<DataModelRelation>();
            InheritanceRelations = new List<InheritanceRelation>();
        }
        public DataTable CreateTable()
        {
            DataTable dataTable = new DataTable(Code);
            foreach (PropertyMate pm in PropertyMetas)
            {
                if (!pm.dataType.StartsWith("$"))
                {
                    dataTable.Columns.Add(new DataColumn(pm.propertyName, DataTypeDict.DataType2CsharpType(pm.dataType)));
                }

            }
            return dataTable;
        }
    }
}
